package com.cartoon.service.impl;

import com.cartoon.entity.HistorySearch;
import com.cartoon.dao.HistorySearchDao;
import com.cartoon.service.HistorySearchService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (HistorySearch)表服务实现类
 *
 * @author makejava
 * @since 2021-12-10 20:54:54
 */
@Service("historySearchService")
public class HistorySearchServiceImpl implements HistorySearchService {
    @Resource
    private HistorySearchDao historySearchDao;

    /**
     * 通过ID查询单条数据
     *
     * @param historyid 主键
     * @return 实例对象
     */
    @Override
    public HistorySearch queryById(Integer historyid) {
        return this.historySearchDao.queryById(historyid);
    }

    /**
     * 分页查询
     *
     * @param historySearch 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<HistorySearch> queryByPage(HistorySearch historySearch, PageRequest pageRequest) {
        long total = this.historySearchDao.count(historySearch);
        return new PageImpl<>(this.historySearchDao.queryAllByLimit(historySearch, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param historySearch 实例对象
     * @return 实例对象
     */
    @Override
    public HistorySearch insert(HistorySearch historySearch) {
        this.historySearchDao.insert(historySearch);
        return historySearch;
    }

    /**
     * 修改数据
     *
     * @param historySearch 实例对象
     * @return 实例对象
     */
    @Override
    public HistorySearch update(HistorySearch historySearch) {
        this.historySearchDao.update(historySearch);
        return this.queryById(historySearch.getHistoryid());
    }

    /**
     * 通过主键删除数据
     *
     * @param historyid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer historyid) {
        return this.historySearchDao.deleteById(historyid) > 0;
    }
}
